package com.wangcanxuan.www.controller.Impl;


import com.wangcanxuan.www.controller.UserController;
import com.wangcanxuan.www.entity.dto.ResultInfo;
import com.wangcanxuan.www.entity.po.Role;
import com.wangcanxuan.www.entity.po.User;

import com.wangcanxuan.www.proxy.ServiceProxy;
import com.wangcanxuan.www.service.Impl.UserServiceImpl;
import com.wangcanxuan.www.service.UserService;


/**
 * 用户界面的Controller层实现类
 *
 * @author HHLJ
 * @date 2022/03/28
 */
public class UserControllerImpl implements UserController {
    private final UserService userService = ServiceProxy.getProxyInstance(UserServiceImpl.class);


    @Override
    public ResultInfo<User> login(String userName, String password) {
        ResultInfo<User> resultInfo =  userService.login(userName, password);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("登录成功");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<String> register(User user) {
        ResultInfo<String> resultInfo =  userService.register(user);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("注册成功");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<Role> getUserRole(String userId) {
        return userService.getUserRole(userId);
    }

    @Override
    public ResultInfo<User> signIn(String id) {
        ResultInfo<User> resultInfo =  userService.signIn(id);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("拉伸成功！");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<User> refresh(String id) {
        return userService.refresh(id);
    }

    @Override
    public ResultInfo<String> updateUserMessage(User user) {
        ResultInfo<String> resultInfo =  userService.updateUserMessage(user);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("更新个人信息成功！");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<String> findPassword(User user) {
        ResultInfo<String> resultInfo =  userService.findPassword(user);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("找回密码成功！");
        }
        return resultInfo;
    }


}
